<?php
require_once APP . '/application/controllers/FrontAction.php';

/**
 * 首页
 */
class IndexController extends FrontAction
{
    
    /**
     * 首页
     *
     */
    public function indexAction()
    {
    	global $cfg;
    	
    	$data = array();
    	$obj_list = new Alllist($this->db);
    	    	
    	// 读取图片新闻
    	$data['tpxw'] = $this->db->fetchAll("select * from article where cid=? order by seq desc, aid desc limit 5", array($cfg['listtype']['tpxw']));
    	
    	// 读取新闻公告
    	$data['tzgg'] = $this->db->fetchAll("select * from article where cid=? order by seq desc, aid desc limit 2", array($cfg['listtype']['tzgg']));
    	
    	// 读取新闻聚焦
    	$data['xwjj'] = $this->db->fetchAll("select * from article where cid=? and recommend=1 order by seq desc, aid desc limit 1 ", array(1));
    	$aid = 0;
    	foreach ($data['xwjj']  as $v){
    		$aid = $v['aid'];
    	}
    	$data['xwjj_list'] = $this->db->fetchAll("select * from article where cid=? and aid!=$aid order by seq desc, aid desc limit 3 ", array(1));
    	
    	// 读取专题报道
    	$data['ztbd'] = $this->db->fetchAll("select t1.* from article t1  where cid=? order by seq desc, aid desc limit 4 ", array(2));
    	// 读取学术活动
    	$arr_types = $obj_list->getAllListByType($cfg['listtype']['xshd'], false);
    	$str = implode(",", array_keys($arr_types));
    	$data['xshd'] = array();
    	if (!empty($str))
    		$data['xshd'] = $this->db->fetchAll("select t1.* from article t1  where cid in(?) and recommend=1 order by recseq desc,seq desc, aid desc limit 5 ", array($str));
    	
    	// 读取出版物
    	$arr_types = $obj_list->getAllListByType($cfg['listtype']['publication'], false);
    	$sql = array();
    	foreach ($arr_types as $typeid => $v)
    		$sql[] = "(select pid,typeid,`name`,author,keywords,intro,image,pdf,down,seq,adminid,syncpid from publication where typeid=" . $typeid . ' order by seq desc, pid desc limit 1)';
    	
    	if (count($sql) > 0){    		
    		$data['publication'] = $this->db->fetchAll(implode(" union ", $sql));
    	}else{
    		$data['publication'] = array();
    	}
    	
    	// 读取论坛人物
    	$arr_types = $obj_list->getAllListByType($cfg['listtype']['ltrw'], false);
    	$str = implode(",", array_keys($arr_types));
    	$data['ltrw_top'] = array();
    	$data['ltrw_list'] = array();
    	if (!empty($str)){
    		$data['ltrw_top'] = $this->db->fetchAll("select t1.* from article t1  where cid in(?) and recommend=1 order by recseq desc, seq desc, aid desc", array($str));
    		$data['ltrw_list'] = $this->db->fetchAll("select t1.* from article t1 where cid in(?) and recommend=0 order by seq desc, aid desc limit 4 ", array($str));
    	}    	
    	
    	$this->view->idata = $data;    	    	
    	$this->render("index");
    }
    
}
